<?
include('./header.inc');
include('./database.inc');
	
if (!isset($_POST['sid']) || !isset($_POST['image'])){
	header( 'Location: ./slides.php' ) ;
	die();
}
$sid = mysql_real_escape_string($_POST['sid']);
$image = $_POST['image'];



if (!isset($_POST['submitted'])){
	header( 'Location: ./newslide.php' ) ;
	die();
}

$query1 = "SELECT * FROM slides WHERE slide_id='$sid'";

$result1 = mysql_query($query1);

$row = mysql_fetch_array( $result1 );

$folder = $row['folder'];
$filename = $row[$image.'file'];

$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension1 = end(explode(".", $_FILES["file"]["name"]));

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& in_array($extension1, $allowedExts)){
	
} else {
	notify("error", "Invalid Image Uploaded");
	header( "Location: ./editslideimage.php?sid=$sid&image=$image" ) ;
	die();
}

if ($_FILES['file']['error'] > 0){
	notify("error", "Error Uploading Image");
	header( "Location: ./editslideimage.php?sid=$sid&image=$image" ) ;
	die();
}


unlink("../images/$folder/$filename");
move_uploaded_file($_FILES['file']["tmp_name"], "../images/$folder/$image.$extension1");



notify("success", "Slide Updated");
header( 'Location: ./slides.php' ) ;

?>